#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM centos:7

LABEL maintainer="kolin <168052730@qq.com>"

RUN yum install -y java-1.8.0-openjdk-devel.x86_64 unzip gettext nmap-ncat openssl, which gnupg, telnet \
 && yum clean all -y

ARG version

ENV BROKER_CLUSTER_NAME="RocketMQCluster"
ENV NAMESRV_ADDR=""
ENV BROKER_ID=0
ENV BROKER_ROLE="ASYNC_MASTER"
ENV POD_NAME=""
ENV STATEFULSET_NAME=""
ENV BROKER_NAME_PREFIX="broker"
ENV BROKER_NAME=""
ENV AUTO_CREATE_TOPIC_ENABLE=true
ENV AUTO_CREATE_SUBSCRIPTION_GROUP=true
ENV DELETE_WHEN=4
ENV FILE_RESERVED_TIME=120
ENV MAPED_FILE_SIZE_COMMIT_LOG=1073741824
ENV MAPED_FILE_SIZE_CONSUME_QUEUE=300000
ENV SEND_MESSAGE_THREAD_POOL_NUMS=16
ENV PULL_MESSAGE_THREAD_POOL_NUMS=""
ENV BROKER_IP1=""
ENV BROKER_IP2=""

ENV ROCKETMQ_VERSION ${version}
ENV LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.UTF-8" 
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
WORKDIR ${ROCKETMQ_HOME}

RUN set -eux; \
    curl -L https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
    curl -L https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
    curl -L https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
    \
    gpg --import KEYS; \
    gpg --batch --verify rocketmq.zip.asc rocketmq.zip; \
    unzip rocketmq.zip; \
    mv rocketmq*/* .; \
    rmdir rocketmq-*; \
    rm rocketmq.zip rocketmq.zip.asc KEYS

RUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN mkdir -p /data/rocketmq

VOLUME /data/rocketmq

COPY scripts/ ${ROCKETMQ_HOME}/bin/
WORKDIR ${ROCKETMQ_HOME}/bin/

RUN mv runbroker-customize.sh runbroker.sh && \
    chmod a+x runbroker.sh && \
    chmod a+x entrypoint.sh && \
    chmod a+x mqbroker
	
EXPOSE 10909 10911 10912
ENTRYPOINT sh entrypoint.sh
